package com.ruoyi.machine.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.machine.mapper.KwMachineInfoMapper;
import com.ruoyi.machine.domain.KwMachineInfo;
import com.ruoyi.machine.service.IKwMachineInfoService;
import org.springframework.util.CollectionUtils;

/**
 * 主机信息Service业务层处理
 * 
 * @author gonianer
 * @date 2023-11-14
 */
@Service
public class KwMachineInfoServiceImpl implements IKwMachineInfoService 
{
    @Autowired
    private KwMachineInfoMapper kwMachineInfoMapper;

    /**
     * 查询主机信息
     * 
     * @param id 主机信息主键
     * @return 主机信息
     */
    @Override
    public KwMachineInfo selectKwMachineInfoById(Long id)
    {
        return kwMachineInfoMapper.selectKwMachineInfoById(id);
    }

    @Override
    public KwMachineInfo selectKwMachineInfoByIp(String ip)
    {
        KwMachineInfo machine = new KwMachineInfo();
        machine.setIp(ip);
        List<KwMachineInfo> machines = this.selectKwMachineInfoList(machine);
        return CollectionUtils.isEmpty(machines)?null:machines.get(0);
    }

    /**
     * 查询主机信息列表
     * 
     * @param kwMachineInfo 主机信息
     * @return 主机信息
     */
    @Override
    public List<KwMachineInfo> selectKwMachineInfoList(KwMachineInfo kwMachineInfo)
    {
        return kwMachineInfoMapper.selectKwMachineInfoList(kwMachineInfo);
    }

    /**
     * 新增主机信息
     * 
     * @param kwMachineInfo 主机信息
     * @return 结果
     */
    @Override
    public int insertKwMachineInfo(KwMachineInfo kwMachineInfo)
    {
        kwMachineInfo.setCreateTime(DateUtils.getNowDate());
        return kwMachineInfoMapper.insertKwMachineInfo(kwMachineInfo);
    }

    /**
     * 修改主机信息
     * 
     * @param kwMachineInfo 主机信息
     * @return 结果
     */
    @Override
    public int updateKwMachineInfo(KwMachineInfo kwMachineInfo)
    {
        kwMachineInfo.setUpdateTime(DateUtils.getNowDate());
        return kwMachineInfoMapper.updateKwMachineInfo(kwMachineInfo);
    }

    /**
     * 批量删除主机信息
     * 
     * @param ids 需要删除的主机信息主键
     * @return 结果
     */
    @Override
    public int deleteKwMachineInfoByIds(Long[] ids)
    {
        return kwMachineInfoMapper.deleteKwMachineInfoByIds(ids);
    }

    /**
     * 删除主机信息信息
     * 
     * @param id 主机信息主键
     * @return 结果
     */
    @Override
    public int deleteKwMachineInfoById(Long id)
    {
        return kwMachineInfoMapper.deleteKwMachineInfoById(id);
    }

}
